package com.time.workbench.system.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.time.workbench.core.util.AuthUtil;
import com.time.workbench.system.entity.bo.SystemDict;
import com.time.workbench.system.entity.bo.SystemGarbage;
import com.time.workbench.system.entity.vo.SystemDictVO;
import com.time.workbench.system.mapper.SystemDictMapper;
import com.time.workbench.system.mapper.SystemGarbageMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class SystemDictService extends ServiceImpl<SystemDictMapper, SystemDict> {

    public List<SystemDictVO> getByTypeCode(String typeCode) {
        return lambdaQuery().eq(SystemDict::getTypeCode, typeCode).list().stream().map(item -> {
            SystemDictVO systemDictVO = new SystemDictVO();
            BeanUtils.copyProperties(item, systemDictVO);
            return systemDictVO;
        }).collect(Collectors.toList());
    }


    /**
     * 转换为map
     * @param typeCode
     * @return
     */
    public Map<String,String> getMapByTypeCode(String typeCode) {
        List<SystemDictVO> systemDictVOS = getByTypeCode(typeCode);
        return systemDictVOS.stream().collect(Collectors.toMap(SystemDictVO::getValue, SystemDictVO::getName));
    }
}
